home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / imlib / scroller.c < prev    next >
C/C++ Source or Header  |  1996-04-11  |  16KB  |  718 lines

  1. #include "scroller.hpp"
  2. #define HS_ICON_W 10
  3. #define HS_ICON_H 8
  4.  
  5.  
  6. unsigned char hs_left_arrow[10*8]={
  7.     0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
  8.     0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  9.     1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  10.     1, 1, 1, 1, 2, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2,
  11.     0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
  12.     2, 0, 0, 0, 0};
  13.  
  14.  
  15. unsigned char hs_right_arrow[10*8]={
  16.     0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  17.     0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
  18.     0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1,
  19.     1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0,
  20.     0, 0, 0, 0, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 2,
  21.     1, 1, 0, 0, 0};
  22.  
  23.  
  24. unsigned char vs_up_arrow[8*10]={
  25.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 0,
  26.     0, 0, 0, 1, 1, 1, 1, 2, 0, 0, 1, 2, 1, 1, 2,
  27.     1, 2, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 1, 1,
  28.     2, 0, 0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 1,
  29.     1, 2, 0, 0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0,
  30.     0, 2, 2, 0, 0};
  31.  
  32.  
  33. unsigned char vs_down_arrow[8*10]={
  34.     0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 1, 1, 2, 0,
  35.     0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 1, 1, 2,
  36.     0, 0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 1, 1,
  37.     2, 0, 0, 0, 1, 2, 1, 1, 2, 1, 2, 0, 0, 1, 1,
  38.     1, 1, 2, 0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0,
  39.     0, 0, 0, 0, 0};
  40.  
  41. void show_icon(image *screen, window_manager *wm, int x, int y, int icw, int ich, unsigned char *buf)
  42. {
  43.   short cx1,cy1,cx2,cy2;
  44.   screen->get_clip(cx1,cy1,cx2,cy2);
  45.   unsigned char remap[3];
  46.   remap[0]=wm->medium_color();
  47.   remap[1]=wm->bright_color();
  48.   remap[2]=wm->dark_color();
  49.  
  50.   for (int yc=ich;yc;yc--,y++)
  51.   {
  52.     if (y>=cy1 && y<=cy2)
  53.     {
  54.       unsigned char *sl=screen->scan_line(y)+x;
  55.       for (int xc=icw,xo=x;xc;xc--,xo++,sl++,buf++)
  56.       {
  57.     if (xo>=cx1 && xo<=cx2)
  58.       *sl=remap[*buf];
  59.       }
  60.     }
  61.   }
  62.   screen->add_dirty(x,y,x+icw-1,y+ich-1);
  63. }
  64.  
  65. scroller::scroller(int X, int Y, int ID, int L, int H, int Vert, int Total_items, ifield *Next)
  66. {  x=X; y=Y; id=ID; next=Next;  l=L; h=H;  sx=0;  t=Total_items;  drag=-1; vert=Vert;
  67. }
  68.  
  69.  
  70. void scroller::area(int &x1, int &y1, int &x2, int &y2, window_manager *wm)
  71. {  
  72.   area_config(wm);
  73.   x1=x-1; y1=y-1;  
  74.   if (vert)
  75.   { x2=x+l+bw();  y2=y+h; }
  76.   else
  77.   { x2=x+l;  y2=y+h+bh(); }
  78. }
  79.  
  80. void scroller::dragger_area(int &x1, int &y1, int &x2, int &y2)
  81. {  
  82.   if (vert)
  83.   { x1=x+l; y1=y+bh(); x2=x+l+bw()-1; y2=y+h-bh()-1; }
  84.   else { x1=x+bw(); y1=y+h; x2=x+l-bw(); y2=y+h+bh()-1; }
  85. }
  86.  
  87. int scroller::bh() { if (vert) return 15; else return 13; }
  88. int scroller::bw() { if (vert) return 12; else return 14; }
  89.  
  90. unsigned char *scroller::b1()
  91. {
  92.   if (vert) return vs_up_arrow;
  93.   else return hs_left_arrow;
  94. }
  95.  
  96. unsigned char *scroller::b2()
  97. {
  98.   if (vert) return vs_down_arrow;
  99.   else return hs_right_arrow;
  100. }
  101.  
  102.  
  103. void scroller::draw_first(image *screen, window_manager *wm)
  104. {
  105.   if (sx>=t) sx=t-1;
  106.   draw(0,screen,wm);
  107.   screen->wiget_bar(b1x(),b1y(),b1x()+bw()-1,b1y()+bh()-1,
  108.             wm->bright_color(),wm->medium_color(),wm->dark_color());
  109.   screen->wiget_bar(b2x(),b2y(),b2x()+bw()-1,b2y()+bh()-1,
  110.             wm->bright_color(),wm->medium_color(),wm->dark_color());
  111.   show_icon(screen,wm,b1x()+2,b1y()+2,bw()-4,bh()-4,b1());
  112.   show_icon(screen,wm,b2x()+2,b2y()+2,bw()-4,bh()-4,b2());
  113.  
  114.   int x1,y1,x2,y2;
  115.   dragger_area(x1,y1,x2,y2);
  116.   screen->bar(x1,y1,x2,y2,wm->black());
  117.   screen->bar(x1+1,y1+1,x2-1,y2-1,wm->medium_color());   
  118.   draw_wiget(screen,wm,0);
  119.   scroll_event(sx,screen,wm);
  120. }
  121.  
  122. void scroller::wig_area(int &x1, int &y1, int &x2, int &y2)
  123. {
  124.   int sx1,sy1,sx2,sy2;
  125.   dragger_area(sx1,sy1,sx2,sy2);
  126.   if (vert)
  127.   {
  128.     x1=x+l+1;
  129.     if (t<2)
  130.       y1=y+bh()+1;
  131.     else
  132.       y1=y+bh()+1+sx*(sy2-sy1+1-bh())/(t-1);
  133.   } else
  134.   {
  135.     if (t<2) x1=x+bw()+1;
  136.     else x1=x+bw()+1+sx*(sx2-sx1+1-bw())/(t-1);
  137.     y1=y+h+1;
  138.   }
  139.   x2=x1+bw()-3;
  140.   y2=y1+bh()-3;  
  141.   
  142. }
  143.  
  144.  
  145. void scroller::draw_wiget(image *screen, window_manager *wm, int erase)
  146.   int x1,y1,x2,y2;
  147.   wig_area(x1,y1,x2,y2);
  148.   if (erase)
  149.     screen->bar(x1,y1,x2,y2,wm->medium_color());
  150.   else
  151.     screen->wiget_bar(x1,y1,x2,y2,
  152.               wm->bright_color(),wm->medium_color(),wm->dark_color());
  153. }
  154.  
  155. void scroller::draw(int active, image *screen, window_manager *wm)
  156. {
  157.   int x1,y1,x2,y2;
  158.   area(x1,y1,x2,y2,wm);
  159.   screen->rectangle(x1,y1,x2,y2,active ? wm->bright_color() : wm->dark_color());
  160. }
  161.  
  162.  
  163. void scroller::handle_event(event &ev, image *screen, window_manager *wm, input_manager *inm)
  164. {
  165.   int mx=ev.mouse_move.x,my=ev.mouse_move.y;
  166.   switch (ev.type)
  167.   {
  168.     case EV_MOUSE_BUTTON :
  169.     {
  170.       if (ev.mouse_button && drag==-1)
  171.       {    
  172.     if (mx>=b1x() && mx<b1x()+bw() && my>=b1y()-2 && my<b1y()+bh())
  173.     {
  174.       if (sx>0)
  175.       {
  176.         draw_wiget(screen,wm,1);
  177.         sx--;
  178.         draw_wiget(screen,wm,0);
  179.         scroll_event(sx,screen,wm);
  180.       }
  181.     } else if (mx>=b2x() && mx<b2x()+bw() && my>=b2y() && my<=b2y()+bh())
  182.     {
  183.       if (sx<t-1)
  184.       {
  185.         draw_wiget(screen,wm,1);
  186.         sx++;
  187.         draw_wiget(screen,wm,0);
  188.         scroll_event(sx,screen,wm);
  189.       }        
  190.     }
  191.     else
  192.     {
  193.       int dx1,dy1,dx2,dy2;
  194.       dragger_area(dx1,dy1,dx2,dy2);
  195.       if (mx>=dx1 && mx<=dx2 && my>=dy1 && my<=dy2)
  196.       {
  197.         int x1,y1,x2,y2;
  198.         wig_area(x1,y1,x2,y2);
  199.         if (mx>=x1 && mx<=x2 && my>=y1 && my<=y2)
  200.         {
  201.           drag=sx;
  202.           inm->grab_focus(this);
  203.         }          
  204.         else if (t>1)
  205.         {
  206.           int nx=mouse_to_drag(mx,my);
  207.           if (nx!=sx && nx>=0 && nx<t)
  208.           {
  209.         draw_wiget(screen,wm,1);
  210.         sx=nx;
  211.         draw_wiget(screen,wm,0);
  212.         scroll_event(sx,screen,wm);        
  213.           }        
  214.         }
  215.       } else handle_inside_event(ev,screen,wm,inm);
  216.     }
  217.       } else if (!ev.mouse_button && drag!=-1)
  218.       {
  219.     inm->release_focus();
  220.     drag=-1;
  221.       }
  222.     } break;
  223.  
  224.     case EV_MOUSE_MOVE :
  225.     {
  226.       if (drag!=-1)
  227.       {
  228.     int nx=mouse_to_drag(mx,my);
  229.     if (nx<0) nx=0; else if (nx>=t) nx=t-1;
  230.     if (nx!=sx)
  231.     {
  232.       draw_wiget(screen,wm,1);
  233.       sx=nx;
  234.       draw_wiget(screen,wm,0);
  235.       scroll_event(sx,screen,wm);
  236.     }
  237.       } else if ( activate_on_mouse_move())
  238.       {
  239.     int x1,y1,x2,y2;
  240.     wig_area(x1,y1,x2,y2);
  241.     if (mx>=x && mx<=x+l-1 && my>=y && my<=y+h-1)
  242.       handle_inside_event(ev,screen,wm,inm);
  243.       }
  244.  
  245.     } break;
  246.     case EV_KEY :
  247.     {
  248.       switch (ev.key)
  249.       {
  250.     case JK_LEFT : 
  251.     { handle_left(screen,wm,inm); } break;
  252.     case JK_RIGHT : 
  253.     { handle_right(screen,wm,inm); } break;
  254.     case JK_UP : 
  255.     { handle_up(screen,wm,inm); } break;
  256.     case JK_DOWN : 
  257.     { handle_down(screen,wm,inm); } break;
  258.  
  259.     default :
  260.       handle_inside_event(ev,screen,wm,inm);
  261.       }
  262.     } break;
  263.   }
  264. }
  265.  
  266.  
  267. void scroller::handle_right(image *screen, window_manager *wm, input_manager *inm)
  268. {
  269.   if (!vert && sx<t-1)
  270.   {
  271.     draw_wiget(screen,wm,1);
  272.     sx++;
  273.     draw_wiget(screen,wm,0);
  274.     scroll_event(sx,screen,wm);        
  275.   }
  276. }
  277.  
  278. void scroller::handle_left(image *screen, window_manager *wm, input_manager *inm)
  279. {
  280.   if (!vert && sx>1)
  281.   {
  282.     draw_wiget(screen,wm,1);
  283.     sx--;
  284.     draw_wiget(screen,wm,0);
  285.     scroll_event(sx,screen,wm);        
  286.   }
  287. }
  288.  
  289. void scroller::handle_up(image *screen, window_manager *wm, input_manager *inm)
  290.   if (vert && sx>1)
  291.   {
  292.     draw_wiget(screen,wm,1);
  293.     sx--;
  294.     draw_wiget(screen,wm,0);
  295.     scroll_event(sx,screen,wm);        
  296.   }
  297. }
  298.  
  299. void scroller::handle_down(image *screen, window_manager *wm, input_manager *inm)
  300. {
  301.   if (vert && sx<t-1)
  302.   {
  303.     draw_wiget(screen,wm,1);
  304.     sx++;
  305.     draw_wiget(screen,wm,0);
  306.     scroll_event(sx,screen,wm);        
  307.   }
  308. }
  309.  
  310. void scroller::set_x (int x, image *screen, window_manager *wm)
  311. {
  312.   if (x<0) x=0;
  313.   if (x>=t) x=t-1;
  314.   if (x!=sx)
  315.   {
  316.     draw_wiget(screen,wm,1);
  317.     sx=x;
  318.     draw_wiget(screen,wm,0);
  319.     scroll_event(sx,screen,wm);        
  320.   }
  321. }
  322.  
  323. int scroller::mouse_to_drag(int mx,int my)
  324. {
  325.   int x1,y1,x2,y2;
  326.   dragger_area(x1,y1,x2,y2);
  327.   
  328.   if (vert)
  329.   {
  330.     int h=(y2-y1+1-bh());
  331.     if (h) 
  332.       return (my-y-bh()-bh()/2)*(t-1)/h;
  333.     else return 0;
  334.   }
  335.   else 
  336.   {
  337.     int w=(x2-x1+1-bw());
  338.     if (w)
  339.       return (mx-x-bw()-bw()/2)*(t-1)/w;
  340.     else return 0;
  341.   }
  342. }
  343.  
  344.  
  345. void scroller::scroll_event(int newx, image *screen, window_manager *wm)
  346. {
  347.   screen->bar(x,y,x+l-1,y+h-1,wm->black());
  348.   int xa,ya,xo,yo;
  349.   if (vert) { xa=0; ya=30; yo=x+5; yo=y+5; } else { xa=30; ya=0; xo=x+5; yo=y+5; }
  350.   for (int i=newx,c=0;c<30 && i<100;i++,c++)
  351.   {
  352.     char st[10];
  353.     sprintf(st,"%d",i);
  354.     wm->font()->put_string(screen,xo,yo,st,wm->bright_color());
  355.     xo+=xa; yo+=ya;
  356.   }
  357. }
  358.  
  359. void pick_list::area_config(window_manager *wm)
  360. {
  361.   l=wid*wm->font()->width();
  362.   h=th*(wm->font()->height()+1);  
  363. }
  364.  
  365. int lis_sort(void const *a, void const *b)
  366. {
  367.   pick_list_item *a1=(pick_list_item *)a;
  368.   pick_list_item *a2=(pick_list_item *)b;
  369.   return strcmp(a1->name,a2->name);
  370. }
  371.  
  372. pick_list::pick_list(int X, int Y, int ID, int height,
  373.         char **List, int num_entries, int start_yoffset, ifield *Next, image *texture)
  374.      : scroller(X,Y,ID,2,2,1,0,Next)
  375. {
  376.   th=height;
  377.   tex=texture;
  378.   t=num_entries;
  379.   wid=0;
  380.   key_hist_total=0;
  381.   lis=(pick_list_item *)jmalloc(sizeof(pick_list_item)*num_entries,"pick list");
  382.   int i=0;
  383.   for (;i<num_entries;i++)
  384.   {
  385.     lis[i].name=List[i];
  386.     lis[i].number=i;
  387.   }
  388.   qsort((void *)lis,num_entries,sizeof(pick_list_item),lis_sort);
  389.  
  390.   for (i=0;i<t;i++)
  391.     if (strlen(List[i])>wid) 
  392.       wid=strlen(List[i]);
  393.   cur_sel=sx=start_yoffset;
  394. }
  395.  
  396. void pick_list::handle_inside_event(event &ev, image *screen, window_manager *wm, input_manager *inm)
  397. {
  398.   if (ev.type==EV_MOUSE_MOVE && activate_on_mouse_move())
  399.   {
  400.     int sel=last_sel+(ev.mouse_move.y-y)/(wm->font()->height()+1);
  401.     if (sel!=cur_sel && sel<t && sel>=0)
  402.     {
  403.       cur_sel=sel;
  404.       scroll_event(last_sel,screen,wm);
  405.     }    
  406.   }
  407.   else if (ev.type==EV_MOUSE_BUTTON)
  408.   {  
  409.     int sel=last_sel+(ev.mouse_move.y-y)/(wm->font()->height()+1);
  410.     if (sel<t && sel>=0)
  411.     {
  412.       if (sel==cur_sel)
  413.       wm->push_event(new event(id,(char *)this));
  414.       else 
  415.       {
  416.     cur_sel=sel;
  417.     scroll_event(last_sel,screen,wm);
  418.       }      
  419.     }
  420.   } else if (ev.type==EV_KEY && ev.key==JK_ENTER)  
  421.     wm->push_event(new event(id,(char *)this));
  422.   else if (ev.type==EV_KEY)
  423.   {
  424.     int found=-1;
  425.     if (key_hist_total<20)
  426.       key_hist[key_hist_total++]=ev.key;
  427.  
  428.     for (int i=0;i<t && found==-1;i++)
  429.     {
  430.       if (strlen(lis[i].name)>=key_hist_total && memcmp(lis[i].name,key_hist,key_hist_total)==0)
  431.     found=i;
  432.     }
  433.     if (found!=-1)
  434.     {
  435.       sx=found;
  436.       cur_sel=found;
  437.       scroll_event(sx,screen,wm);
  438.     } else key_hist_total=0;
  439.   }
  440. }
  441.  
  442. void pick_list::handle_up(image *screen, window_manager *wm, input_manager *inm)
  443. {
  444.   if (cur_sel>0)
  445.     cur_sel--;
  446.   else return ;
  447.   if (cur_sel<sx)
  448.   {
  449.     draw_wiget(screen,wm,1);
  450.     sx=cur_sel;
  451.     draw_wiget(screen,wm,0);
  452.   }
  453.   scroll_event(sx,screen,wm);              
  454. }
  455.  
  456. void pick_list::handle_down(image *screen, window_manager *wm, input_manager *inm)
  457. {
  458.   if (cur_sel<t-1)
  459.     cur_sel++;
  460.   else return ;
  461.   if (cur_sel>sx+th-1)
  462.   {
  463.     draw_wiget(screen,wm,1);
  464.     sx=cur_sel-th+1;
  465.     draw_wiget(screen,wm,0);
  466.   }
  467.   scroll_event(sx,screen,wm);              
  468. }
  469.  
  470. void pick_list::scroll_event(int newx, image *screen, window_manager *wm)
  471. {
  472.   last_sel=newx;
  473.   if (tex)
  474.   {
  475.     short cx1,cy1,cx2,cy2;
  476.     screen->get_clip(cx1,cy1,cx2,cy2);
  477.     screen->set_clip(x,y,x+l-1,y+h-1);
  478.     int tw=(l+tex->width()-1)/tex->width();
  479.     int th=(h+tex->height()-1)/tex->height();
  480.     int dy=y,dx;
  481.     for (int j=0;j<th;j++,dy+=tex->height())
  482.       for (int i=0,dx=x;i<tw;i++,dx+=tex->width())      
  483.         tex->put_image(screen,dx,dy);
  484.  
  485.     screen->set_clip(cx1,cy1,cx2,cy2);
  486.   } else screen->bar(x,y,x+l-1,y+h-1,wm->black());
  487.  
  488.   int dy=y;
  489.   for (int i=0;i<th;i++,dy+=wm->font()->height()+1)
  490.   {
  491.     if (i+newx==cur_sel)
  492.       screen->bar(x,dy,x+wid*wm->font()->width()-1,dy+wm->font()->height(),wm->dark_color());
  493.     if (i+newx<t)
  494.       wm->font()->put_string(screen,x,dy,lis[i+newx].name,wm->bright_color());
  495.   } 
  496. }
  497.  
  498.  
  499.  
  500.  
  501. spicker::spicker(int X, int Y, int ID, int Rows, int Cols, int Vert, int MultiSelect, 
  502.            ifield *Next)
  503.      : scroller(X,Y,ID,2,2,Vert,0,Next)
  504. {
  505.   l=-1;
  506.   last_click=-1;
  507.   r=Rows;
  508.   c=Cols;
  509.   m=MultiSelect;
  510.   select=NULL;
  511. }
  512.  
  513. void spicker::set_select(int x, int on)
  514. {
  515.   if (m)
  516.   {
  517.     if (on)
  518.       select[x/8]|=1<<(x&7);
  519.     else
  520.       select[x/8]&=(0xff-(1<<(x&7)));
  521.   } else cur_sel=x;  
  522. }
  523.  
  524. int spicker::get_select(int x)
  525. {
  526.   if (m)
  527.     return select[x/8]&(1<<(x&7));
  528.   else return (x==cur_sel);
  529. }
  530.  
  531. int spicker::first_selected()
  532. {
  533.   if (m)
  534.   {
  535.     for (int i=0;i<t;i++)
  536.       if (get_select(i)) return i;
  537.     return -1;
  538.   } else return cur_sel;
  539. }
  540.  
  541. void spicker::reconfigure()
  542. {
  543.   if (select)
  544.     jfree(select);
  545.   select=NULL;
  546.  
  547.  
  548.   t=total();
  549.   if (sx>t)
  550.     sx=t-1;
  551.   if (m)
  552.   {
  553.     select=(uchar *)jmalloc((t+7)/8,"selection bit array");
  554.     memset(select,0,(t+7)/8);
  555.   } else cur_sel=0;
  556. }
  557.  
  558. void spicker::draw_background(window_manager *wm, image *screen)
  559. {
  560.   screen->bar(x,y,x+l-1,y+h-1,wm->dark_color());
  561. }
  562.  
  563.  
  564. void spicker::area_config(window_manager *wm)
  565. {
  566.   if (vert)
  567.     l=item_width(wm)+4;
  568.   else
  569.     l=item_width(wm)*c+4;
  570.  
  571.   if (vert)
  572.     h=item_height(wm)*r+4;
  573.   else
  574.     h=item_height(wm)+4;
  575.  
  576. }
  577.  
  578. void spicker::set_x(int x, image *screen, window_manager *wm)
  579. {
  580.   cur_sel=x;
  581.   sx=x;
  582.   scroll_event(x,screen,wm);
  583. }
  584.  
  585.  
  586. void spicker::scroll_event(int newx, image *screen, window_manager *wm)
  587. {
  588.   last_sel=newx;
  589.   int xa,ya,xo,yo;
  590.   xo=x+2;
  591.   yo=y+2;
  592.   if (vert) { xa=0; ya=item_height(wm); }
  593.   else { xa=item_width(wm); ya=0; }
  594.   draw_background(wm,screen);
  595.  
  596.   for (int i=newx;i<newx+vis();i++)
  597.   {
  598.     if (i<t)
  599.     {
  600.       if (m)      
  601.         draw_item(wm,screen,xo,yo,i,get_select(i));
  602.       else
  603.         draw_item(wm,screen,xo,yo,i,i==cur_sel);
  604.     }
  605.     xo+=xa; yo+=ya;
  606.   }
  607. }
  608.  
  609.  
  610. void spicker::handle_inside_event(event &ev, image *screen, window_manager *wm, input_manager *inm)
  611. {
  612.   switch (ev.type)
  613.   {
  614.     case EV_MOUSE_MOVE :
  615.     {
  616.       if (activate_on_mouse_move())
  617.       {
  618.     int me;      
  619.     if (vert)
  620.       me=last_sel+(ev.mouse_move.y-y)/item_height(wm);
  621.     else
  622.       me=last_sel+(ev.mouse_move.x-x)/item_width(wm);
  623.     if (me<t && me>=0)
  624.     {
  625.       if (cur_sel!=me)
  626.       {
  627.         cur_sel=me;
  628.         scroll_event(last_sel,screen,wm);
  629.         note_new_current(wm,screen,inm,me);
  630.       }
  631.     }
  632.       }
  633.     } break;
  634.     case EV_MOUSE_BUTTON :
  635.     {
  636.       int me;      
  637.       if (vert)
  638.     me=last_sel+(ev.mouse_move.y-y)/item_height(wm);
  639.       else
  640.     me=last_sel+(ev.mouse_move.x-x)/item_width(wm);
  641.       if (me<t && me>=0)
  642.       {
  643.     if (m)
  644.     {      
  645.       if (ev.mouse_button)
  646.       {
  647.         if (ok_to_select(me))
  648.         {
  649.           set_select(me,!get_select(me));
  650.           scroll_event(last_sel,screen,wm);
  651.           inm->grab_focus(this);
  652.         }
  653.       } else last_click=-1;
  654.  
  655.     } else if (ok_to_select(me))
  656.     {
  657.       if (cur_sel==me)        
  658.         note_selection(wm,screen,inm,me);
  659.       else
  660.       {
  661.         cur_sel=me;
  662.         scroll_event(last_sel,screen,wm);
  663.         note_new_current(wm,screen,inm,me);
  664.       }
  665.     }
  666.       }
  667.     } break;
  668.   }
  669. }
  670.  
  671.  
  672.  
  673. void spicker::handle_up(image *screen, window_manager *wm, input_manager *inm)
  674. {
  675.   if (vert && cur_sel>0)
  676.   {
  677.     cur_sel--;
  678.  
  679.     if (cur_sel<sx)
  680.     {
  681.       draw_wiget(screen,wm,1);
  682.       last_sel=sx=cur_sel;
  683.       draw_wiget(screen,wm,0);
  684.     }
  685.     scroll_event(last_sel,screen,wm);
  686.     note_new_current(wm,screen,inm,cur_sel);    
  687.   }
  688. }
  689.  
  690. void spicker::handle_down(image *screen, window_manager *wm, input_manager *inm)
  691. {
  692.   if (vert && cur_sel<t-1)
  693.     cur_sel++;
  694.   else return ;
  695.   if (cur_sel>sx+r-1)
  696.   {
  697.     draw_wiget(screen,wm,1);
  698.     last_sel=sx=cur_sel-r+1;
  699.     draw_wiget(screen,wm,0);
  700.   }
  701.   scroll_event(sx,screen,wm);
  702.   note_new_current(wm,screen,inm,cur_sel);    
  703. }
  704.  
  705. void spicker::handle_left(image *screen, window_manager *wm, input_manager *inm)
  706. {
  707. }
  708.  
  709. void spicker::handle_right(image *screen, window_manager *wm, input_manager *inm)
  710. {
  711. }
  712.  
  713.  
  714.  
  715.  
  716.